# Contributor: Guy Godfroy <guy.godfroy@gugod.fr>
# Maintainer: Guy Godfroy <guy.godfroy@gugod.fr>
pkgname=haproxy-dataplaneapi
_pkgname=dataplaneapi
pkgver=3.0.1
pkgrel=0
pkgdesc="HAProxy data plane API"
url="https://github.com/haproxytech/dataplaneapi"
# loongarch64: incompatible github.com/shirou/gopsutil
arch="all !loongarch64"
license="Apache-2.0"
makedepends="go"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc"
source="$_pkgname-$pkgver.tar.gz::https://github.com/haproxytech/dataplaneapi/archive/refs/tags/v$pkgver.tar.gz
	haproxy-dataplaneapi.initd
	haproxy-dataplaneapi.confd
	dataplaneapi.yml
	"
options="net"
builddir="$srcdir/$_pkgname-$pkgver"

build() {
	export LD_FLAGS="\
		-X main.Version=$pkgver \
		-X main.GitTag=$pkgver \
		-X main.GitCommit=release \
		-X main.GitDirty= \
		-X main.GitRepo=$url \
		-X main.BuildTime=$(date -u '+%Y-%m-%dT%H:%M:%SZ') \
		"
	go build -ldflags="${LD_FLAGS}" -o dataplaneapi $builddir/cmd/dataplaneapi/main.go
}

check() {
	# TestReloadAgentDoesntMissReloads needs systemd
	go test -skip TestReloadAgentDoesntMissReloads ./...
}

package() {
	install -m755 -D "$builddir"/dataplaneapi \
		"$pkgdir"/usr/sbin/dataplaneapi
	install -m644 -D "$srcdir"/dataplaneapi.yml \
		"$pkgdir"/etc/haproxy/dataplaneapi.yml
	install -m755 -D "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd \
		"$pkgdir"/etc/conf.d/$pkgname
}

sha512sums="
5a6d142d88c352108dcdf106006f98b42ed90a17c114fda3e4f8831f77b4496acf7c5e47ffe7680ae101ff5811020cde9c596bf48283abd457bdcd6591ca0e47  dataplaneapi-3.0.1.tar.gz
29f0f6f489f0b163eae7945bd53c663f95c608aeadc2437545933020b33357f019f0bb50840ea88ff80e645b2082210fef9590ff2013d5b49c60e2c3d85e81ad  haproxy-dataplaneapi.initd
76c173820d513de762e6834ad3dcaf53695d2a8f6bb2340c0a50be769fdb9abd1a63a254d5ea4a51bcf8d7a8edd1d9b531aa73974cffbed5d95be05e111b2211  haproxy-dataplaneapi.confd
95b843518ecc90c0bf052982c12a4de5f2b3d2d98fc831a85ad22508ba25b01739e1d3cd8318c22369771dad765f2e45059cb5094b8456be6bbc084bff3136be  dataplaneapi.yml
"
